import CommonConstant from "../../constant/CommonConstant";
import BasePanel from "./BasePanel";
import EnumData from "../../Enum/EnumData";
import { utils } from "../../utils/CommonUtil";

export default class LoadingPanel extends BasePanel {

    private m_LoadingProgress: fairygui.GProgressBar;
    private m_content: fairygui.GLabel;
    private m_progressTitle: fairygui.GLabel;

    constructor(id) {
        super();

        this.m_fui = fairygui.UIPackage.createObject("LoadingPanel", "LoadingPanel").asCom;
        this.m_LoadingProgress = this.m_fui.getChild("loadingProgress").asProgress;
        this.m_progressTitle = this.m_fui.getChild("value").asLabel;
        this.m_content = this.m_fui.getChild("loadingTip").asLabel;
     
        this.m_nameID = id;
        this.InitUI();
    }

    private InitUI() {
        window.gameFacade.SceneMng.AddFUI(this.m_fui);
        this.SetProgress(0);
        var r: Number = Math.round(Math.random() * 10 + 1);
        super.Show();
    }

    public SetProgress(value: number): void {
        this.m_LoadingProgress.value = Math.round(value * 100);
        this.m_progressTitle.text = Math.round(value * 100) + "%";
        if (this.m_LoadingProgress.value > this.m_LoadingProgress.max) {
            this.m_LoadingProgress.value = this.m_LoadingProgress.max;
        }
    }

    public SetContent(content: string) {
        this.m_content.text = content;
    }
}